<template>
    <div>
        <el-button type="info" icon="el-icon-back" circle style="margin-left:-900px "
                   @click="$router.push({path:'/tc_shopmall_tj'})">返回销售
        </el-button>
        <div id="Bigdiv">
            <h1>查询商品编号</h1>
            商品名称:
            <el-input
                    placeholder="请输入商品名称"
                    v-model="name"
                    clearable
                    :on-icon-click="pchandleIconClick"  @keyup.enter.native="searchEnterFun" :plain="true">
            </el-input>

            <br/>
            商品编号:
            <el-input
                    placeholder="商品编号"
                    v-model="spbh"
                    :disabled="true">
            </el-input>
        </div>
        <h2 style="font-family: 华文彩云;color: teal">请熟记商品对应的商品编号!</h2>
    </div>
</template>

<script>
    export default {
        data() {
            return {
                name:'',
                price: '',
                storeid:'',
                spbh: '',
                kc: {
                    quantity: ''
                }
            }
        },
        beforeRouteEnter(to, from, next) {
            next(vm => {
                vm.loadData();
            });
        },
        methods: {
            loadData: function () {
                var vm = this;
                this.axios.post("/getname")
                    .then(function (response) {
                        vm.storeid = response.data.storeid;
                    }).catch((error) => {

                })
            },

            searchEnterFun: function (e) {
                alert(this.storeid)
                var vm = this;
                var keyCode = window.event ? e.keyCode : e.which;
                this.axios.get('/getIdByNamed', {
                    params: {
                        storeid:this.storeid,
                        name:this.name
                    }
                })
                    .then(function (response) {
                        vm.spbh = response.data;
                    }).catch((error)=>{
                    this.$message({
                        showClose: true,
                        message: '您所在的店铺没有该商品!',
                        type: 'warning'
                    });
                })
            }
        }
    }
</script>

<style scoped>
    .el-input {
        width: 180px;
    }
    #Bigdiv{
        padding-top: 20px;
    }
</style>
